package com.cristina.attention.rest;

import com.cristina.attention.entity.Group;
import com.cristina.attention.entity.vo.GroupVo;
import com.cristina.attention.service.GroupService;
import com.cristina.attention.mp.support.Condition;
import com.cristina.attention.utils.R;
import com.cristina.attention.utils.api.ResultCode;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @Author superman
 * @Date 2021/11/13 18:52
 **/
@Slf4j
@RestController
@RequestMapping("core/group")
@AllArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /**
     * 查询单条
     * @param group
     * @return
     */
    @ApiOperation(value = "查看详情", notes = "传入id")
    @GetMapping("/detail")
    public R<Object> detail(Group group) {
        Group detail = groupService.getOne(Condition.getQueryWrapper(group));
        return R.data(detail);
    }

    /**
     * 查询单条
     */
    @ApiOperation(value = "查看详情", notes = "传入id")
    @GetMapping("/info")
    public R<Object> info(Group group) {
        Group detail = groupService.getById(group.getGroupId());
        return R.data(detail);
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R<Object> list() {
        return R.data(groupService.list());
    }

    /**
     * 新增或修改
     */
    @ApiOperation(value = "新增或修改", notes = "传入groupVo")
    @PostMapping("/create")
    public R<Object> create(@RequestBody GroupVo groupVo) {
        return R.status(groupService.create(groupVo));
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改", notes = "传入groupVo")
    @PostMapping("/invite")
    public R<Object> invite(@RequestBody GroupVo groupVo) {
        return R.status(groupService.invite(groupVo));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除", notes = "传入groupId")
    @PostMapping("/dissolution/{groupId}")
    public R<Object> dissolution(@PathVariable Long groupId) {
        return R.status(groupService.dissolution(groupId));
    }

    @ApiOperation(value = "查询所属群聊", notes = "传入userId")
    @GetMapping("/findGroupBelonging/{userId}")
    public R<Object> findGroupBelonging(@PathVariable Long userId) {
        return R.data(groupService.findGroupBelonging(userId));
    }

}
